package definePresent.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import definePresent.model.PresentBean;
import model.User;

/**
 * Servlet implementation class DescribePresent
 */
@WebServlet("/DescribePresent")
public class DescribePresent extends HttpServlet {
	private static final long serialVersionUID = 1L;
 
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession();
		User user = (User) session.getAttribute("user");
		if(user==null || !user.getAccountType().equals("S")){
			response.sendRedirect("Login.html");
			return;
		}
		request.setCharacterEncoding("UTF-8");
		session.setAttribute("define", "present");
		String description = request.getParameter("description");
		int count = Integer.parseInt(request.getParameter("count"));
		PresentBean present = new PresentBean(description, count);
		session.setAttribute("present", present);
		response.sendRedirect("/Store/upload/upload.jsp");
	}

}
